<template>
  <div class="writer-app_home_index">
    <div class="home_top">
      <div class="home_top_title"></div>

      <div class="Carousel_map">
        <van-swipe
          class="my-swipe"
          :autoplay="4000"
          :touchable="true"
          indicator-color="white"
        >
          <van-swipe-item class="Carousel_map_img1">1</van-swipe-item>
          <van-swipe-item class="Carousel_map_img2">2</van-swipe-item>
        </van-swipe>
      </div>
    </div>

    <div class="mid_option">
      <van-row type="flex" justify="space-around">
        <van-col span="4" class="item1" replace to="/order">
          <router-link to="/order">
            <div class="png"></div>
            <p class="png_p">订单</p>
          </router-link>
        </van-col>
        <van-col span="4" class="item2" replace to="/money">
          <router-link to="/money">
            <div class="png"></div>
            <p class="png_p">收益</p>
          </router-link>
        </van-col>
        <van-col span="4" class="item3">
          <router-link to="">
            <div class="png"></div>
            <p class="png_p">帮助</p>
          </router-link>
        </van-col>
        <van-col span="4" class="item4" replace to="/mine">
          <router-link to="/mine">
            <div class="png"></div>
            <p class="png_p">我的</p>
          </router-link>
        </van-col>
      </van-row>
    </div>
    <div class="order_form">
      <div class="order_form_title">
        <span>我的订单</span>
      </div>
      <div class="order_form_content">
        <!-- <router-link to="/orderdetails"> -->
        <div
          class="order_item"
          v-for="(item, index) in categoryData"
          :key="index"
          @click="toClick(item.id)"
        >
          <div class="order_form_flex_item1">
            <img
              :src="item.customer.userFace"
              alt=""
              width="100%"
              height="100%"
            />
          </div>
          <div class="order_form_flex_item2">
            <span class="flex_item2_name">{{ item.customer.username }}</span>
            <span class="flex_item2_status">{{ item.status }}</span>
            <p class="flex_item2_address">
              <span
                >{{ item.address.province }}{{ item.address.city
                }}{{ item.address.area }}{{ item.address.address }}</span
              >
            </p>
            <div class="flex_item2_date_pirce">
              <div class="flex_item2_date">
                {{ formatDate(item.orderTime) }}
              </div>
              <div
                class="flex_item2_pirce"
              >
                {{temp[index]}}￥
              </div>
            </div>
          </div>
        </div>
        <!-- </router-link> -->
      </div>
    </div>
  </div>
</template>

<script>
import index_page from "@/styles/index_page.css";
import { getToken } from "@/utils/auth";
import { info, pageQuery } from "@/api/index";
import { Toast } from 'vant';
// import Vue from 'vue'

// Vue.use(Toast);

export default {
  data() {
    return {
      categoryData: [],
      // categoryDataProduct:[],
      employeeId: [],
      temp: [],
    };
  },
  computed: {},
  methods: {
    // async takeToken() {
    //   const res = await info({ token: getToken() });
    //   // const employeeId = [];
    //   this.employeeId = res.data.id;
    //   // this.Ttoken = res.data.list;
    //   // console.log(Ttoken);
    //   // console.log(res.data.id);
    // },
    
    async queryCategoryData() {
      // const res = await pageQuery({
      //   page: 1,
      //   pageSize: 100,
      //   employeeId: this.employeeId,
      // });
      Toast.loading({ message: '加载中...', forbidClick: true, overlay:true , duration:0});

      const res = await info({ token: getToken() });
      // const employeeId = [];
      this.employeeId = res.data.id;

      const abs = await pageQuery({
        page: 1,
        pageSize: 100,
        employeeId: this.employeeId,
      });
      this.categoryData = abs.data.list;
      this.forAdd();
      Toast.clear();

      // console.log(res);
    },

    formatDate(row, column) {
      let date = new Date(parseInt(row));
      let Y = date.getFullYear() + "-";
      let M =
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1) + "-"
          : date.getMonth() + 1 + "-";
      let D =
        date.getDate() < 10 ? "0" + date.getDate() + " " : date.getDate() + " ";
      let h =
        date.getHours() < 10
          ? "0" + date.getHours() + ":"
          : date.getHours() + ":";
      let m =
        date.getMinutes() < 10
          ? "0" + date.getMinutes() + ":"
          : date.getMinutes();
      // let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
      return Y + M + D + h + m;
    },

    printf(arr){
      console.log(arr);
    },

    toClick(id) {
      // console.log(id);
      this.$router.push({
        path: "/Details",
        query: {
          index: id,
        },
      });
    },

    forAdd() {
      let i = 0, j = 0, k = 0, x = [], y = 0;
      for (let key in this.categoryData) {
        // console.log(this.tabList[key].orderLines);

        this.categoryData[key].orderLines;
        for (let key1 in this.categoryData[key].orderLines) {
          
          for(let j = 0; j <= parseInt(key); j++){
            if(j === parseInt(key)){

              if(parseInt(key1) !== 0){
                x[i] = x[i] + this.categoryData[key].orderLines[key1].price;
                // console.log('经过1.1');

              }else{
                x[j] = this.categoryData[key].orderLines[key1].price;
                // console.log('经过1.2');

              }
              // console.log('经过1');

            }else if(j + 1 < parseInt(key)){
              x[j+1] = 0;
              // console.log('经过2');

            }
            // console.log('j=',j,'x=',x,'key=',parseInt(key),'key1=',parseInt(key1),'x[i]=',x[i]);

          }

          // console.log('i=',i,'x=',x,'key=',parseInt(key),'key1=',parseInt(key1),'x[i]=',x[i]);
          this.temp = x;
          // console.log(this.temp);

          i++;
          
        }
        
      }
    }
  },
  created() {
    this.queryCategoryData();
    // this.queryData()
    // this.takeToken();
  },
  mounted() {},
};
</script>
<style scoped>
</style>